package com.apps.Im.Tencent.aspect.impl;

import com.alibaba.fastjson.JSONObject;
import com.apps.sexctption.DataException;
import com.apps.sexctption.NullException;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

@Slf4j
@Aspect
@Component
@Configuration
public class TencentRestApiAspect {


    @Pointcut("@annotation(com.apps.Im.Tencent.aspect.TencentRestApi)")
    public void pointcut() {

    }

    @Around("pointcut()")
    public Object doAround(ProceedingJoinPoint point) throws Throwable {
        //真实执行方法
        JSONObject result= (JSONObject) point.proceed();
        if(null == result)
            throw new NullException("腾讯IM接口返回空");
        //校验返回接口
        if(result.getString("ActionStatus").equals("FAIL"))
            throw new DataException(result.getString("ErrorCode")+"----"+result.getString("ErrorInfo"));
        return result;
    }
}
